/**
 * 
 */
package com.zrt.pad.commonui;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

/**
 * @author ASUS
 *
 */
public class SingleSelect {
	private AlertDialog.Builder dialogBuilder;
	private SingleSelectInterface delegate;
	private int selectType;
	private List<? extends Object> itemList;
	public SingleSelect(Context context, String title, String[] items, List<? extends Object> theList, 
			SingleSelectInterface theDelegate, int theSelectType){
		this.delegate = theDelegate;
		this.selectType = theSelectType;
		this.itemList = theList;
		dialogBuilder = new AlertDialog.Builder(context);
		dialogBuilder.setTitle(title);
		dialogBuilder.setItems(items, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				if(delegate != null){
					Object item = itemList.get(which);
					delegate.onSingleSelectDone(which, item, selectType);
				}
				
			}
		});
		dialogBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				if (delegate != null){
					delegate.onSingleSelectCancel(selectType);
				}
				
			}
		});
	}
	
	public void showDialog(){
		dialogBuilder.show();
	}
}